package com.itheima.dao;

import com.itheima.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    @Select(" SELECT * FROM tb_user ")//查询所有
    List<User> findall();



    @Select(" SELECT * FROM tb_user ")//查询所有并且映射到指定到实体类中
    @Results({
            @Result(column = "id",property = "id", id = true),//映射主键 对应
            @Result(column = "user_name",property = "userName")//名字不同对应
    })
    List<User> findall2();



    @Insert(" INSERT INTO tb_user VALUES(null,#{userName},#{password},#{name},#{age},#{sex})")
    void addUser(User user);//添加用户信息



    @Insert(" INSERT INTO tb_user VALUES(null,#{userName},#{password},#{name},#{age},#{sex})")
    @Options(useGeneratedKeys = true,keyColumn ="id" ,keyProperty ="id")
    Integer addUser2(User user);//添加用户信息 并且 获取他自增的id的值


    @Update(" UPDATE tb_user SET user_name=#{userName},password=#{password},name=#{name},age=#{age},sex=#{sex} where id=#{id}" )
    void updateuser(User user);//按照指定id修改


    @Delete(" DELETE FROM tb_user WHERE id=#{id}")
    void deletebyID(@Param("id")String id);//删除指定id用户
}
